#pragma once
#include "rbtree.h"
template<class k, class v>
class map
{
public:
    struct mapkeyoft
    {
        const k& operator()(const pair<k, v>& kv)
        {
            return kv.first;
        }
    };
    typedef typename rbtree<k,pair<const k,v>,mapkeyoft>::Iterator iterator;
    typedef typename rbtree<k, pair<const k, v>, mapkeyoft>::const_Iterator const_iterator;
    void insert(pair<k,v> p)
    {
        _rbtree.insert(p);
    }
    iterator begin()
    {
        return _rbtree.begin();
    }
    iterator end()
    {
        return _rbtree.end();
    }
    const_iterator begin() const
    {
        return _rbtree.begin();
    }
    const_iterator end() const 
    {
        return _rbtree.end();
    }
    v& operator[](const k& key)
    {
        pair<iterator, bool> ret = _rbtree.insert({key, v()});
        return ret.first->second;
    }
    iterator find(const k& key)
    {
        return _rbtree.find(key);
    }
private:
    rbtree<k, pair<const k, v>, mapkeyoft> _rbtree;//map中的pair里的key是不能修改的
};